﻿<#include "/common/easyui-css.html">
<#include "/common/easyui-js.html">
<#include "/common/loading.html">
<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/easyui/datagrid-detailview.js"></script>

<body class="easyui-layout">
<div class="easyui-layout" style="width:100%;height:100%;">
            <!-- 主表  -->
            <table id="config_table" class="easyui-datagrid" title="" style="width:100%;height:100%;padding-bottom: 2px;"
                   data-options="rownumbers:true, pagination:true,singleSelect:true,url:'/config-list/1/20',
                              method:'get',
                              toolbar:'#tb',
                              loadMsg : '数据加载中',
                              fitColumns : true,
                             showFooter: true" >
                <thead>
                    <tr>
                        <th data-options="field:'entityName', width:50" >实体名称</th>
                        <th data-options="field:'tableName', width:50" >表名称</th>
                        <th data-options="field:'parentMenuNameKey', width:50" >父目录名称ID</th>
                        <th data-options="field:'selfMenuNameRout', width:50" >本目录路径</th>
                        <th data-options="field:'selfMenuNameValue', width:50" >本目录名称Value</th>
                        <th data-options="field:'isGenerate', width:50" >是否已经生成</th>
                    </tr>
                </thead>
            </table>
        </div>


<!-- 详细 -->
<script type="text/javascript">
    $('#config_table').datagrid({
        view: detailview,
        detailFormatter: function(rowIndex, rowData){
            return '<table><tr>' +
                    '<td style="border:0">' +
                    '<p><span style="font-weight:bold">属性列表</span>: ' + rowData.entityAttribute + '</p>' +
                    '</td>' +
                    '</tr></table>';
        }
    });
</script>

<!-- 搜索框 -->
<div id="tb" style="padding:5px;height:auto">
	<div>
        模板名称1:<input class="easyui-textbox" id="to" style="width:120px" >
		<a href="#" class="easyui-linkbutton" iconCls="icon-search" id="searchByParameter">搜索</a>
	</div>
    <div style="margin:5px 0;"></div>
    <#include "/common/button.html">
</div>

<div id="dlg" class="easyui-dialog" style="width:800px" data-options="closed:true,modal:true,border:'thin',buttons:'#dlg-buttons'">
    <form id="fm" method="post" novalidate style="margin:0;padding:20px 50px">
        <div style="margin-bottom:10px">
            <input name="entityName" class="easyui-textbox" required="true" label="实体名称:" missingMessage="请输入实体名称" style="width:100%">
        </div>

        <div style="margin-bottom:10px">
            <input name="entityAttribute" class="easyui-textbox" style="width:100%" required="true" label="属性类型对:" missingMessage="请输入属性类型对" style="">
        </div>
        <div style="margin-bottom:10px">
            <input id="parentMenuNameKey" class="easyui-combobox" name="parentMenuNameKey" required="true" missingMessage="请输入父目录" style="width:100%" label="父目录名称ID" data-options="valueField:'value',
                                        textField:'key',
                                        url:'/menu-key-value',
                                        editable: true,
                                        onChange:function(){
                                            $(this).combobox('getValue');
                                         }">
        </div>
        <div style="margin-bottom:10px">
            <input name="selfMenuNameValue" class="easyui-textbox" required="true" label="本目录名称Value:" missingMessage="请输入本目录名称Value" style="width:100%">
        </div>
    </form>
</div>
<div id="dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveConfig()" style="width:90px">Save</a>
    <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">Cancel</a>
</div>


<!-- 按钮操作 -->
<script type="text/javascript">
    var url;
    //新增
    $("#add").click(function () {
        $('#dlg').dialog('open').dialog('center').dialog('setTitle','新增实体');
        $('#fm').form('clear');
        url = '/config-ins-upd-del/-1';
    })
    //编辑
    $("#edit").click(function () {
        var row = $('#config_table').datagrid('getSelected');
        if (row){
            $('#dlg').dialog('open').dialog('center').dialog('setTitle','编辑实体');
            $('#fm').form('load',row);
            url = '/config-ins-upd-del/'+row.id;
        } else {
            layer.msg("请选择需要修改的实体",{icon: 2})
        }
    });
    //行复制
    $("#copy").click(function () {
        var row = $('#config_table').datagrid('getSelected');
        if (row){
            $('#dlg').dialog('open').dialog('center').dialog('setTitle','复制实体');
            $('#fm').form('load',row);
            url = '/config-ins-upd-del/-1'
        } else {
            layer.msg("请选择需要复制的实体",{icon: 2})
        }
    });
    function saveConfig(){
        $('#fm').form('submit',{
            url: url,
            onSubmit: function(){
                return $(this).form('validate');
            },
            success: function(result){
                $('#dlg').dialog('close');        // close the dialog
                $('#config_table').datagrid('reload');    // reload the user data
            }
        });
    }
    //删除
    $("#delete").click(function () {
        var row = $('#config_table').datagrid('getSelected');
        if(!row){
            layer.msg("请选择需要删除的实体",{icon: 2})
        }else{
            url = '/config-ins-upd-del/'+row.id;
            $.messager.confirm('删除信息','确定删除此实体?',function(r){
                if (r){
                    $.post(url,{deleteFlag:'Y',tm:new Date()},function(result){
                        $('#config_table').datagrid('reload');    // reload the user data
                    });
                }
            });
        }
    })

    $('#generate').click(function () {
        var row = $('#config_table').datagrid('getSelected');
        if(!row){
            layer.msg("请选择需要生成的实体",{icon: 2})
        }else if(row&&row.isGenerate=='Y'){
            layer.msg("已经生成，请确认",{icon: 2})
        }else if(row&&row.isGenerate=='N'){
            url = '/config-generate/'+row.id;
            $.messager.confirm('生成实体','确定生成实体?',function(r){
                if (r){
                    $.post(url,{tm:new Date()},function(result){
                        $('#config_table').datagrid('reload');    // reload the user data
                    });
                }
            });

            // var index = '';
            // var tm = new Date();
            // $.ajax({
            //     url :'/config-generate',
            //     data : {id :row.id,entityName:row.entityName,entityAttribute:row.entityAttribute,tableName:row.tableName,tm:tm},
            //     async : true,
            //     beforeSend: function (request) {
            //         index = layer.load(1, {
            //             shade: [0.5,'#ffffcc'] //0.1透明度的白色背景
            //         });
            //     },
            //     success : function(){
            //         layer.close(index);
            //         $('#config_table').datagrid('reload');
            //     }
            // });
        }
    })
    
</script>

<!-- 分页 -->
<script type="text/javascript">
	$(function(){
		var p = $('#config_table').datagrid().datagrid('getPager');
		p.pagination({
			pageSize: 20, //每页显示的记录条数，默认为10
			pageList: [20, 40, 60], //可以设置每页记录条数的列表
			onSelectPage: function (pageNumber, pageSize) {
			    if(pageNumber==0){
			        pageNumber = 1;
                }
				var handler = '/config-list/'+pageNumber+"/"+pageSize;
				$('#config_table').datagrid('options').url = handler;
				$('#config_table').datagrid('reload');
			}
		});
	})
</script>
